package com.sojson.project.sys.menu.entity.bo;

import java.io.Serializable;
import java.util.List;
import java.util.stream.Collectors;

import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.sojson.config.converter.fastjson.NullNoOutFeature;
import com.sojson.project.sys.dept.entity.vo.DeptVo;
import com.sojson.project.sys.menu.entity.vo.MenuVo;
import com.sojson.util.StringUtil;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
 * Treeselect树结构实体类
 * 
 * @author liu
 * @date 2021-05-18
 */
@Data
@ApiModel("下拉列表Bean")
public class TreeSelect implements Serializable {
    private static final long serialVersionUID = 1L;

    /** 节点ID */
    @ApiModelProperty("节点ID")
    private String id;
    /** 节点名称 */
    @ApiModelProperty("节点名称")
    private String label;
    /** 子节点 */
    @JsonInclude(JsonInclude.Include.NON_EMPTY)
    @JSONField(serializeUsing = NullNoOutFeature.class)
    @ApiModelProperty("子节点")
    private List<TreeSelect> children;

    public TreeSelect() {

    }

    public TreeSelect(MenuVo dto) {
        this.id = dto.getId();
        this.label = dto.getName();
        List<MenuVo> c = dto.getChildren();
        if (StringUtil.isNotBlankObject(c) && c.size() > 0) {
            this.children = dto.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList());
        }
    }

    public TreeSelect(DeptVo dto) {
        this.id = dto.getId();
        this.label = dto.getName();
        List<DeptVo> c = dto.getChildren();
        if (StringUtil.isNotBlankObject(c) && c.size() > 0) {
            this.children = dto.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList());
        }
    }

}